package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.SensitiveDto;
import com.heima.model.wemedia.dtos.WmMaterialUpdateDto;
import com.heima.model.wemedia.pageQuery.MediaPageQuery;
import com.heima.model.wemedia.pojos.WmMaterial;
import com.heima.model.wemedia.pojos.WmSensitive;
import com.heima.wemedia.service.WmSensitiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("/api/v1/sensitive")
public class WmSensitiveController {
    @Autowired
    private WmSensitiveService wmSensitiveService;
    @PostMapping("/list")
    public PageResponseResult page (@RequestBody MediaPageQuery mediaPageQuery){
        return wmSensitiveService.pageByName(mediaPageQuery);
    }

    /**
     * 新增敏感词
     * @param dto
     * @return
     */
    @PostMapping("save")
    public ResponseResult save(@RequestBody SensitiveDto dto){
      boolean r=  wmSensitiveService.save(dto);
        return  r?ResponseResult.okResult(AppHttpCodeEnum.SUCCESS):ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
    }
    /**
     * 修改敏感词
     */
    @PostMapping("update")
    public ResponseResult update(@RequestBody WmSensitive wmSensitive){
        return wmSensitiveService.updateNameById(wmSensitive)?ResponseResult.okResult(AppHttpCodeEnum.SUCCESS):ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
    }
    /**
     * 删除敏感词
     */
    @DeleteMapping("del/{id}")
    public ResponseResult delete(@PathVariable Integer id){
        return wmSensitiveService.removeById(id)?ResponseResult.okResult(AppHttpCodeEnum.SUCCESS):ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
    }

}
